Skip to content

feat: add openai responses api capability #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

arvi18
Copy link

@arvi18 arvi18 commented Apr 27, 2025

Updates ai and @ai-sdk/openai versions to support the new OpenAI Responses API.
Updates the default "small" and "large" models to use the Responses API.
Adds a new webSearchPreview tool call to demo the new OpenAI Web Search Preview tool.

Summary by CodeRabbit

  • New Features

    • Integrated a web search preview tool into chat, enhancing responses when certain models are selected.
  • Bug Fixes

    • Corrected a typo in error messages for improved clarity.
  • Chores

    • Updated dependencies for improved stability and compatibility.

@arvi18
Copy link
Author

arvi18 commented Apr 27, 2025

@matthewmichel is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@arvi18
Copy link
Author

arvi18 commented Apr 27, 2025

New and updated dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@ai-sdk/[email protected]1.2.2 None +6 5.83 MB vercel-release-bot
npm/[email protected]4.1.54 environment, network +14 9.11 MB chriswdmr, ijjk, matheuss, ...8 more

View full report↗︎

@arvi18
Copy link
Author

arvi18 commented Apr 27, 2025

the timeline of this pr is the reason why open source is the future.

@arvi18
Copy link
Author

arvi18 commented Apr 27, 2025

Sort and sweet. Love it!

Copy link

coderabbitai bot commented Apr 27, 2025

Walkthrough

The changes update the integration with the OpenAI SDK and related dependencies. The chat API handler now conditionally adds a webSearchPreview tool for certain models and disables storage for OpenAI provider options. The instantiation of OpenAI language models is updated to use the .responses() method in the provider configuration. Dependency versions for @ai-sdk/openai and ai are incremented. Additionally, a typo in an error message is corrected.

Changes

File(s) Change Summary
app/(chat)/api/chat/route.ts Imports openai from @ai-sdk/openai, integrates webSearchPreview tool for some models, configures providerOptions with store: false, and fixes a typo in an error message.
lib/ai/providers.ts Updates OpenAI model instantiation to use .responses() method for gpt-4o-mini and gpt-4o.
package.json Bumps @ai-sdk/openai from 1.2.0 to 1.2.2 and ai from 4.1.50 to 4.1.54.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ChatAPI (POST handler)
    participant OpenAI
    participant WebSearchPreview

    Client->>ChatAPI (POST handler): Send chat request
    ChatAPI (POST handler)->>OpenAI: Initialize with providerOptions (store: false)
    alt Model is not "chat-model-reasoning"
        ChatAPI (POST handler)->>WebSearchPreview: Add tool (searchContextSize: medium)
    end
    ChatAPI (POST handler)->>OpenAI: Send chat request with/without tool
    OpenAI-->>ChatAPI (POST handler): Return response
    ChatAPI (POST handler)-->>Client: Return chat response
Loading

Poem

A bunny hops through fields of code,
Upgrading tools along the road.
With search in tow and typos gone,
New versions help the chat move on.
Models respond with extra flair—
The rabbit’s touch is everywhere!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@arvi18
Copy link
Author

arvi18 commented Apr 27, 2025

@tobiasbueschel Changes made to not store messages on the OpenAI side. Open to any other suggestions/feedback.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @arvi18, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on updating the ai and @ai-sdk/openai packages to support the new OpenAI Responses API. It also updates the default "small" and "large" models to utilize this new API. Additionally, a webSearchPreview tool call is added to demonstrate the OpenAI Web Search Preview tool.

Highlights

  • OpenAI Responses API Support: The ai and @ai-sdk/openai packages are updated to support the new OpenAI Responses API.
  • Model Updates: The default 'small' and 'large' models are updated to use the Responses API.
  • Web Search Preview Tool: A new webSearchPreview tool call is added to showcase the OpenAI Web Search Preview tool.

Changelog

Click here to see the changelog
  • app/(chat)/api/chat/route.ts
    • Imported the openai module from @ai-sdk/openai (line 28).
    • Added webSearchPreview to the list of allowed tool calls (line 89).
    • Implemented the webSearchPreview tool using openai.tools.webSearchPreview with a 'medium' search context size (lines 101-103).
    • Added providerOptions to disable storing data for OpenAI (lines 105-107).
    • Corrected a typo in the error message from 'occured' to 'occurred' (line 147).
  • lib/ai/providers.ts
    • Updated the chat-model-small and chat-model-large language models to use openai.responses instead of openai (lines 28-29).
  • package.json
    • Updated the version of @ai-sdk/openai from 1.2.0 to 1.2.2 (line 23).
    • Updated the version of ai from 4.1.50 to 4.1.54 (line 43).
  • pnpm-lock.yaml
    • Updated the version of @ai-sdk/openai from 1.2.0 to 1.2.2 (line 15).
    • Updated the version of ai from 4.1.50 to 4.1.54 (line 75).
    • Updated the integrity hash for @ai-sdk/openai to the new version (line 273).
    • Added @ai-sdk/[email protected] and @ai-sdk/[email protected] as dependencies (lines 288-299).
    • Added @ai-sdk/[email protected] as a dependency (lines 317-327).
    • Added @ai-sdk/[email protected] as a dependency (lines 338-346).
    • Updated the integrity hash for ai to the new version (line 1688).
    • Updated dependencies and integrity hashes for @ai-sdk/openai, @ai-sdk/provider-utils, @ai-sdk/react, @ai-sdk/ui-utils, and ai in the snapshots section (lines 3850-5029).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


The models now respond,
With answers from beyond,
Web search in the mix,
New features to fix,
AI's power unbound.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the OpenAI Responses API, updates default models, and adds a web search preview tool. The changes seem well-structured and aligned with the feature's objective. However, there are a few areas that could benefit from closer attention.

Summary of Findings

  • Error message typo: There's a typo in the error message within app/(chat)/api/chat/route.ts. It should be 'occurred' instead of 'occured'.
  • Tool call naming consistency: Consider whether webSearchPreview is the most descriptive and consistent name for the new tool call, and whether it aligns with existing naming conventions.
  • Dependency updates: The package.json and pnpm-lock.yaml files have been updated with new versions of ai and @ai-sdk/openai. Ensure that these updates have been thoroughly tested and are compatible with the existing codebase.

Merge Readiness

The pull request is almost ready for merging. Addressing the typo in the error message is crucial. Additionally, it would be beneficial to confirm the naming consistency of the new tool call and ensure the dependency updates are thoroughly tested. I am unable to approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issue should be addressed before merging.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 020494f and d74b983.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (3)
  • app/(chat)/api/chat/route.ts (4 hunks)
  • lib/ai/providers.ts (1 hunks)
  • package.json (2 hunks)
🔇 Additional comments (7)
package.json (1)

23-23: Package update to @ai-sdk/[email protected]

The update from 1.2.0 to 1.2.2 is necessary to support the new OpenAI Responses API features used elsewhere in the codebase. This change aligns with the PR objectives.

lib/ai/providers.ts (1)

28-29: Updated model initialization to use Responses API

Excellent modification to switch from openai() to openai.responses() for both small and large models. This change leverages the new OpenAI Responses API which is the key feature being added in this PR.

Note that the models 'title-model' and 'artifact-model' (lines 34-35) still use the traditional openai() function. This appears intentional as the PR seems focused on updating only the chat models.

app/(chat)/api/chat/route.ts (5)

28-28: Added import for OpenAI SDK

Good addition - this import is necessary to support the new webSearchPreview tool implementation.


89-90: Added Web Search Preview tool to active tools

Well implemented addition of the webSearchPreview tool to the list of experimental active tools. The tool is correctly conditionally applied only when not using the reasoning model.


105-109: Disabled storage for OpenAI provider

This change configures the OpenAI provider to not store conversation data (store: false). This is a good practice for privacy and data management, aligning with the updates to use the Responses API.


147-147: Fixed typo in error message

Corrected "occured" to "occurred" - good attention to detail.


101-104:

✅ Verification successful

Implemented Web Search Preview functionality

Good implementation of the webSearchPreview tool using the OpenAI tools API with a medium search context size. This aligns with the PR objective to demonstrate the OpenAI Web Search Preview functionality.


🌐 Web query:

What is the OpenAI Web Search Preview tool and how does it work?

💡 Result:

OpenAI Web Search Preview Tool: Overview and Functionality

What is the OpenAI Web Search Preview Tool?

The OpenAI Web Search Preview tool is a specialized capability integrated into OpenAI's latest generative AI models, notably versions like GPT-4o-search-preview and GPT-4o-mini-search-preview. This tool enables these models to perform real-time web searches as part of their response generation process, allowing them to provide answers with up-to-date, factually grounded information and cite online sources directly in their outputs[1][2][6].

How Does the Web Search Preview Work?

  • Model Integration: The tool is built into specific OpenAI models, which are fine-tuned to both interpret user queries and perform targeted web searches to supplement the model’s knowledge[1][6].

  • API Usage:

    • Chat Completions API: When using models like gpt-4o-search-preview via the Chat Completions API, the model will automatically retrieve information from the web before responding to queries[6]. Developers can configure search options, such as the amount of external context to use, directly in API calls.
    • Responses API: Through the Responses API, the web_search_preview tool can be enabled within the tools parameter. The model decides whether to invoke a web search based on the prompt, especially when questions require information beyond the model’s static knowledge base (knowledge cutoff)[4][5][6]. Developers can also manually guide or enforce tool usage via the tool_choice parameter.
  • Underlying Technology:

    • The web search function is powered by a fine-tuned version of the GPT-4o model, trained using advanced synthetic data techniques and distillation from prior models. It leverages third-party search providers and direct content partnerships to source relevant, current web content[2][7].
    • The model is capable of ingesting retrieved documents, extracting relevant passages, and synthesizing them into a coherent, cited response.
    • Adjustments such as “search_context_size” (low, medium, high) allow developers to balance between comprehensiveness, response speed, and API cost[6][8].
  • Output Quality and Citations: Responses generated using the web search tool include inline citations linked to the original URLs, providing transparency and source traceability for the information presented[3][6].

  • Use Case Customization: The tool can be combined with other built-in tools (e.g., file search), and custom instructions can be layered to achieve complex workflows—such as combining user-specific data with external web information before presenting recommendations[5][7].

How Developers Use It

A typical API call using the web search tool involves specifying the model and enabling web search in the request. Here’s a Python snippet:

from openai import OpenAI

client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4o-search-preview",
    web_search_options={
        "search_context_size": "low",
    },
    messages=[{
        "role": "user",
        "content": "What movie won best picture in 2025?"
    }]
)
print(response.choices[0].message.content)

[6][4][8]

Who Can Access It?

The web search tool is available to API users (developers) and select ChatGPT users (such as Plus and Team subscribers) as of late 2024. It is gradually extending to more user tiers and modalities, including voice and canvas tools[2].


In summary, the OpenAI Web Search Preview tool integrates real-time search into AI responses, bridging the gap between static model knowledge and the dynamic, ever-changing information available on the internet. This empowers developers and end-users to receive current, accurately sourced answers within naturally flowing conversations[2][5][6].

Citations:


Verified Web Search Preview Implementation

The webSearchPreview tool is correctly set up with a medium searchContextSize, ensuring the GPT-4o-search-preview model retrieves and synthesizes up-to-date web content. This meets the PR’s goal to demonstrate the OpenAI Web Search Preview functionality.

@@ -40,7 +40,7 @@
"@vercel/analytics": "^1.3.1",
"@vercel/blob": "^0.24.1",
"@vercel/postgres": "^0.10.0",
"ai": "4.1.50",
"ai": "4.1.54",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Package update to [email protected]

This update from 4.1.50 to 4.1.54 is required to support the OpenAI Responses API implementation. The PR comments indicate this adds 14 new transitive dependencies, which is expected for this feature addition.


🏁 Script executed:

#!/bin/bash
# Verify the compatibility of these packages by checking their latest versions
echo "Checking latest versions of @ai-sdk/openai and ai packages..."
npm view @ai-sdk/openai version
npm view ai version

Length of output: 202


Update ai dependency to the latest published version (4.3.10)
npm registry shows that ai@4.1.54 is two minor releases behind—the current latest is 4.3.10. To pick up bug fixes and improvements beyond the OpenAI Responses API support, please bump the version.

  • File: package.json (line 43)
  • Diff suggestion:
-   "ai": "4.1.54",
+   "ai": "^4.3.10",
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"ai": "4.1.54",
"ai": "^4.3.10",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants